home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BT_FIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.4 KB  |  53 lines

  1. /*  bt_find.c - find function */
  2. #include   "stdio.h"
  3. #include   "btree.h"
  4. #include   "bt_macro.h"
  5.  
  6. extern IX_DESC *pci ;
  7.  
  8. int  find_ix(pe,pix)            /* finds first entry with a key */
  9.   ENTRY *pe ;                /* points to key to be matched */
  10.                     /* store the rec. loc. here  */
  11.   IX_DESC  *pix ;            /* points to index descriptor */
  12.   {                    /* returns success = 1, failure= 0 */
  13.      int   ret ;
  14.      ENTRY tempe ;
  15.  
  16.      pci = pix ;
  17.                     /* be sure target is < dummy */
  18.      if( call(pci->pcomp) (pe,&pci->dx.dume) >= 0 )
  19.     {  go_last(pix) ;        /*  no - position at end */
  20.        return( 1 ) ;        /* and return not equal */
  21.     }
  22.  
  23.      ret = find_level(pci->dx.nl,pe,pci->dx.rb) ;
  24.      if( ret == 0 )            /* if an entry was found */
  25.     {  copy_current(0,&tempe) ;    /* store it's record pointer */
  26.        pe->rptr = tempe.rptr ;
  27.     }
  28.      return( ret ) ;
  29.   }
  30.  
  31.  
  32. int  find_level(l,pe,r)         /* find a key within a level */
  33.   int    l ;                /* the level */
  34.   ENTRY *pe ;                /* the target entry */
  35.   RECPOS   r ;                /* the block to look in */
  36.   {
  37.      BLOCK b ;
  38.      int   ret , off ;
  39.  
  40.      retrieve_block(l,r,&b,CURR) ;    /* get current block */
  41.                     /* look for the key there */
  42.      ret = find_block(pe,&b,&off,pci->pcomp) ;
  43.      CB(1) = r ;            /* make this the current block */
  44.      CO(1) = off ;            /* and offset in the block */
  45.  
  46.      if( l > 0 )            /* now search lower levels */
  47.     ret = find_level(l-1,pe,ENT_ADR(&b,off)->rptr) ;
  48.      return( ret ) ;
  49.   }
  50.  
  51.  
  52.  
  53.